package com.ruoyi.web.controller.linkage.linkageStrategy;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.linkage.Vo.LinkageStrategyVo;
import com.ruoyi.linkage.Vo.TemplateManageUpdateVo;
import com.ruoyi.linkage.Vo.TemplateManageVo;
import com.ruoyi.linkage.domain.LinkageAuthorize;
import com.ruoyi.linkage.domain.LinkagePlcConf;
import com.ruoyi.linkage.domain.LinkageProcessTemplateManage;
import com.ruoyi.linkage.service.ILinkageProcessTemplateManageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 流程模板管理Controller
 *
 * @author pengjie
 * @date 2023-12-20
 */
@RestController
@RequestMapping("/linkage/manage")
public class LinkageProcessTemplateManageController extends BaseController
{
    @Autowired
    private ILinkageProcessTemplateManageService linkageProcessTemplateManageService;

    /**
     * 查询流程模板管理列表
     */
    @PreAuthorize("@ss.hasPermi('linkage:manage:list')")
    @GetMapping("/list")
//    public PageInfo<LinkageProcessTemplateManage> list(TemplateManageVo templateManageVo)
//    {
//        PageInfo<LinkageProcessTemplateManage> pageInfo=linkageProcessTemplateManageService.selectPage(templateManageVo);
//        return pageInfo;
//    }
    public  TableDataInfo list(LinkageStrategyVo linkageStrategyVo)
    {
        PageHelper.startPage(Integer.parseInt(linkageStrategyVo.getPageNum()),Integer.parseInt(linkageStrategyVo.getPageSize()));
        LinkageProcessTemplateManage linkageProcessTemplateManage=new LinkageProcessTemplateManage();
        List<LinkageProcessTemplateManage> list=linkageProcessTemplateManageService.selectLinkageProcessTemplateManageList(linkageProcessTemplateManage);
        return  getDataTable(list);
    }


    /**
     * 导出流程模板管理列表
     */
    @PreAuthorize("@ss.hasPermi('linkage:manage:export')")
    @Log(title = "流程模板管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, LinkageProcessTemplateManage linkageProcessTemplateManage)
    {
        List<LinkageProcessTemplateManage> list = linkageProcessTemplateManageService.selectLinkageProcessTemplateManageList(linkageProcessTemplateManage);
        ExcelUtil<LinkageProcessTemplateManage> util = new ExcelUtil<LinkageProcessTemplateManage>(LinkageProcessTemplateManage.class);
        util.exportExcel(response, list, "流程模板管理数据");
    }

    /**
     * 获取流程模板管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('linkage:manage:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(linkageProcessTemplateManageService.selectLinkageProcessTemplateManageById(id));
    }

    /**
     * 新增流程模板管理
     */
    @PreAuthorize("@ss.hasPermi('linkage:manage:add')")
    @Log(title = "流程模板管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody LinkageProcessTemplateManage linkageProcessTemplateManage)
    {
        return toAjax(linkageProcessTemplateManageService.insertLinkageProcessTemplateManage(linkageProcessTemplateManage));
    }

    /**
     * 修改流程模板管理
     */
    @PreAuthorize("@ss.hasPermi('linkage:manage:edit')")
    @Log(title = "流程模板管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TemplateManageUpdateVo templateManageUpdateVo)
    {
        return toAjax(linkageProcessTemplateManageService.editLinkageProcessTemplateManage(templateManageUpdateVo));
    }

    /**
     * 删除流程模板管理
     */
    @PreAuthorize("@ss.hasPermi('linkage:manage:remove')")
    @Log(title = "流程模板管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(linkageProcessTemplateManageService.deleteLinkageProcessTemplateManageByIds(ids));
    }
}
